﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Luna.Framework.Manifest {
	class ServiceManifestProcessor: IManifestProcessor {

		enum ServiceInstatiation { Singleton, Multiple }

		public bool isSupport(IConfigurationManifest manifest, Type hostManifestType) {
			return "service".Equals(manifest.Name) && hostManifestType.getMember("Context") != null;
		}

		public bool process(IManifestManager manager, IConfigurationManifest manifest, object host, IAppContext context) {
			IAppContext hostContext = host.extractAppContext();
			ServiceInstatiation si = manifest.getProperty<ServiceInstatiation>("instance", ServiceInstatiation.Singleton);
			if (si == ServiceInstatiation.Singleton) {
				hostContext.addService(manifest.applyManifest(hostContext, null));
			}
			return false;
		}
	}
}
